<template>
  <el-row>
    <el-col :span="24">
      <el-table :header-cell-style="{ background: '#f5f5f5' }"
                :data="tableData"
                border
                height="300px"
                class="adminTable">
        <el-table-column prop="system_name"
                         align="center"
                         label="系统名称"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="system_no"
                         align="center"
                         label="系统编号"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop=""
                         align="center"
                         label="负责人"
                         show-overflow-tooltip>
          <template slot-scope="scope">
            {{objAuthRow.contact_name}}
          </template>
        </el-table-column>
        <el-table-column prop=""
                         align="center"
                         label="状态"
                         show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.row.status==2">审核中</span>
            <span v-if="scope.row.status==3">授权</span>
            <span v-if="scope.row.status==4">驳回</span>
          </template>
        </el-table-column>
        <el-table-column label="操作"
                         align="center">
          <template slot-scope="scope">
            <!-- :disabled="scope.row.status==4||scope.row.status==0||scope.row.status==2?false:true" -->
            <el-button type="text"
                       :disabled="scope.row.status==3?true:scope.row.status==4?true:false"
                       @click="onAuthOrFail(scope.row,3)">
              授权
            </el-button>
            <!-- :disabled="scope.row.status==3||scope.row.status==0||scope.row.status==2?false:true" -->
            <el-button type="text"
                       :disabled="scope.row.status==3?true:scope.row.status==4?true:false"
                       @click="onAuthOrFail(scope.row,4)">
              驳回
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-col>
    <el-col :span="24"
            class="bottom-box">
      <el-button @click="onBack">返回</el-button>
      <el-button type="primary"
                 @click="onSure">确定</el-button>
    </el-col>
  </el-row>
</template>

<script>
import { unitManageApi } from "@/services/orgainzeManage";
export default {
  props: {
    judgeAuthOpen: Number,
    objAuthRow: Object,
    authCallBack: Function
  },
  data () {
    return {
      currentPage: 1,
      pagesize: 10,
      total: 0,
      tableData: [],
    }
  },
  methods: {
    //返回
    onBack () {
      this.authCallBack('重置')
    },
    //确定
    onSure () {
      this.authCallBack('确定')
    },
    onAuthOrFail (row, val) {//授权或驳回
      this.$confirm(val == 3 ? '确定"授权"该操作?' : '确定"驳回"该操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        unitManageApi.appAuthOrFail({
          data: {
            comp_system_id: row.comp_system_id,
            type: val
          }
        }).then((res) => {
          if (res.code == 0) {
            this.$message.success('操作成功')
            this.getTableData();
          }
        }).catch((error) => {
          console.log(error)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
      });

      console.log('授权=', row)
    },
    //获取单位管理列表数据(表格)
    getTableData () {
      unitManageApi
        .getAppList({
          params: {
            company_id: this.objAuthRow.company_id,
            // auth_sys_type: 2,
            is_page: 0
          }
        })
        .then(
          res => {
            this.tableData = res.data.list;
          },
          err => {
            console.log(err);
          }
        );
    },
    //申请授权
    appliAuth (row) {
      this.authCallBack(row);
    },
  },
  watch: {
    judgeAuthOpen (n, o) {
      if (this.judgeAuthOpen == 1) {
        this.tableData = [];
        this.getTableData();
      }
      console.log('w-judgeAuthOpen=', n, 'objAuthRow=', this.objAuthRow)
    }
  },
  created () {
    if (this.judgeAuthOpen == 1) {
      this.tableData = [];
      this.getTableData();
    }
    console.log('c-judgeAuthOpen=', this.judgeAuthOpen, 'objAuthRow=', this.objAuthRow)
  }
}
</script>

<style lang="scss" scoped>
.col_pagination {
  padding-bottom: 20px;
  text-align: center;
}
.bottom-box {
  text-align: center;
  margin-top: 20px;
}
</style>